/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ranch.api;

import org.ranch.api.service.ConceptService;
import org.ranch.api.utils.RanchUtil;
import org.ranch.model.ConceptCategory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class contains definition of the default concept categories
 * 
 */
public final class DefaultConceptCategories {
    private static Logger log = LoggerFactory.getLogger(DefaultConceptCategories.class);

    /**
     * default concept categories
     */
    private DefaultConceptCategories() {

    }

    /**
     * the animal type concept category
     */
    @ConceptCategoryAnnotation(
	    description = "The type of an animal e.g. Goat, Cow, Bull",
	    id = "F269F24F-CFB3-4B65-AD23-1CD018B7E68B")
    public static final String ANIMAL_TYPE = "Animal type";

    /**
     * the reponsibility concept category
     */
    @ConceptCategoryAnnotation(
	    description = "The responsiblity held e.g. Owner, Manager, Vetinary etc",
	    id = "32FD204B-A45F-4CC9-BE46-91CD6C287804")
    public static final String RESPONSIBILITY_TYPE = "Responsibility type";

    /**
     * the color concept category
     */
    @ConceptCategoryAnnotation(description = "The animal color e.g. white, black etc",
	    id = "QQQD2DDD-A45F-4CC9-2336-9FFFER287304")
    public static final String COLOR_TYPE = "Colour type";

    /**
     * the health status concept category
     */
    @ConceptCategoryAnnotation(description = "The health status e.g. Sick, Dead etc",
	    id = "222224B-A45F-4CWE-BE11-91VVV2A80Z")
    public static final String HEALTH_STATUS_TYPE = "Health status type";

    /**
     * the breed concept category
     */
    @ConceptCategoryAnnotation(description = "The animal breed e.g.  Hybrids, Local etc",
	    id = "3000UUI-A45F-4CC9-BE46-RTWYWT7768")
    public static final String BREED_TYPE = "Breed type";

    /**
     * the breed concept category
     */
    @ConceptCategoryAnnotation(description = "The animal status e.g.  Sold, Calf etc",
	    id = "30VVVUI-A45F-4CC9-BE46-QQQDDD7768")
    public static final String STATUS_TYPE = "Status type";

    /**
     * array of the default concept categories
     */
    public static final String[] DEFAULT_CONCEPT_CATEGORIES = new String[] { ANIMAL_TYPE,
	    RESPONSIBILITY_TYPE, COLOR_TYPE, HEALTH_STATUS_TYPE, BREED_TYPE, STATUS_TYPE };

    /**
     * gets the id of the field in this class representing the given concept
     * category required
     * 
     * @param conceptCategory
     * @return
     */
    public static final String getConceptCategoryId(String conceptCategory) {
	try {
	    ConceptCategoryAnnotation annotation = RanchUtil.getConceptCategoryFieldAnnotation(
		    DefaultConceptCategories.class, conceptCategory);
	    if (annotation != null) {
		return annotation.id();
	    }

	} catch (SecurityException e) {
	    log.error(null, e);
	} catch (NoSuchFieldException e) {
	    log.error(null, e);
	}

	return null;
    }

    /**
     * gets the {@link ConceptCategory} for the given category name
     * 
     * @param conceptService
     * @param name
     * @return
     */
    public static ConceptCategory getConceptCategory(ConceptService conceptService,
	    String name) {
	return conceptService.getConceptCategoryById(getConceptCategoryId(name));
    }
}
